#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m;
int e[N], ne[N * 2], h[N], w[N], idx;
int dis[N];
void add(int x, int y, int z) {
  e[idx] = y, ne[idx] = h[x], w[idx] = z, h[x] = idx++;
}
int cnt[N];
queue<int> q;
bool inque[N];
int main() {
  memset(h, -1, sizeof h);
  memset(dis, 0x3f, sizeof dis);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    add(x, y, z);
  }
  dis[1] = 0;
  for (int i = 1; i <= n; ++i) {
    q.push(i);
    inque[i] = true;
  }
  while (q.size()) {
    int u = q.front();
    q.pop();
    inque[u] = false;

    for (int i = h[u]; i != -1; i = ne[i]) {
      int v = e[i];
      if (dis[v] > dis[u] + w[i]) {
        cnt[v] = cnt[u] + 1;
        if (cnt[v] >= n) {
          cout << "Yes\n";
          return 0;
        }

        dis[v] = dis[u] + w[i];
        if (!inque[v]) {
          q.push(v);
          inque[v] = true;
        }
      }
    }
  }
  cout << "No\n";
}
